home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3468 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: ohstpy.mps.ohio-state.edu!vancleef
  2. From: vancleef@ohstpy.mps.ohio-state.edu
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help in C
  5. Message-ID: <1996Jan24.033219.8806@ohstpy>
  6. Date: 24 Jan 96 03:32:19 -0500
  7. References: <4e4h29$3f2@cville-srv.wam.umd.edu>
  8. Organization: The Ohio State University, Department of Physics
  9.  
  10. In article <4e4h29$3f2@cville-srv.wam.umd.edu>, leungyl@wam.umd.edu (David Leung) writes:
  11. > I am studying C/C++ and I arrived at a problem that I am stuck with.
  12. > I think it is easy for expericenced programmers, if you can help me
  13. > please email me at leungyl@wam.umd.edu
  14. > this is the problem
  15. > input a five digit number
  16. > then, separate the five digits into 5 separate numbers and evaluate them
  17. > independently. Basically, cut the number into five pieces. This is what
  18. > I wrote.....
  19.  
  20. Read it in as a string and evalute each byte individually. 
  21.  
  22. -Garrett
  23.  
  24.  
  25. > cout <<  "Enter a five digit number: ";
  26. > cin >> input;
  27. > digi1 = input / 10000;
  28. > digi2 = input / 1000 - digi1 * 10;
  29. > digi3 = input / 100 - digi1 * 100 - digi2 * 10;
  30. > digi4 = input / 10 - digi1 * 1000 - digi2 * 100 - digi3 * 10;
  31. > digi5 = input - digi1 * 10000 - digi2 * 1000 - digi3 * 100 - digi4 * 10;
  32. > cout << input << endl;
  33. > cout << digi1 << endl;
  34. > cout << digi2 << endl;
  35. > cout << digi3 << endl;
  36. > cout << digi4 << endl;
  37. > cout << digi5 << endl;
  38. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  39. > the problem is, it work for some numbers, but for others it doesn't work.
  40. > Why? Can somebody help me??Thanks very much.
  41. > Regards,
  42. > David
  43.